// // 导航守卫
import router from '@/router'
import store from '@/store'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
const whitePage = ['/404', '/login']
router.beforeEach((to, from, next) => {
  Nprogress.start()
  if (store.state.user.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whitePage.includes(to.path.toLowerCase())) {
      next()
    } else {
      next('/login')
    }
  }
  Nprogress.done()
})
router.afterEach((to,from) => {
  Nprogress.done()
})
